<?php
/****
	责任链模式
****/
header('Content-type:text/html;charset=utf-8');


class Board{ 
	protected $power = 1;
	protected $higher_level = 'Admin';

	public function process($level){
		if($level <= $this->power){
			echo  "版主删帖";
		}else{
			$top = new $this->higher_level;
			$top->process($level);
		}
	}
}


class Admin{ 
	protected $power = 2;
	protected $higher_level = 'Police';

	public function process($level){
		if($level <= $this->power){
			echo  "管理员封号";
		}else{
			$top = new $this->higher_level;
			$top->process($level);
		}
	}
}

class Police{ 
	protected $power = 3;
	protected $higher_level = null;

	public function process($level){
		echo  "抓起来";
	}
}


//责任链模式处理举报问题,当前级别处理不了，上一级处理
//1，首先，很长的if-else结构或很长switch-case结构不见了，取而代之的是直接把处理情景交给一个责任链即可，代码十分简洁。
//2，之前每个分支的代码，在责任链模式中，会被分布放到不同的处理类中。虽然类的个数不算少，但每个类的指责十分单一，便于维护。
$level = $_POST['jubao'] + 0;
$judge = new Board();
$judge->process($level);



